package com.ylr.admin.common.vo.uri;

import com.ylr.admin.common.enums.UriEnum;
import com.ylr.base.common.jsr303.group.Save;
import com.ylr.base.common.jsr303.group.Update;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-08 15:16:37
 * className: UriVo
 * version: 1.0
 * description:
 */
@Getter
@Setter
@ToString
public class UriVo {

    /**
     * 主键
     */
    @NotNull(message = "主键不能为空", groups = Update.class)
    private Long id;

    /**
     * 父级主键
     */
    @NotNull(message = "父级主键不能为空", groups = { Save.class, Update.class })
    private Long parentId;

    /**
     * 父级路径（‘-’分割）
     */
    @NotBlank(message = "父级路径不能为空", groups = { Save.class, Update.class })
    private String parentPath;

    /**
     * 所属模块
     */
    @NotNull(message = "所属模块不能为空", groups = { Save.class, Update.class })
    private Integer module;

    /**
     * 接口名称
     */
    @NotBlank(message = "接口名称不能为空", groups = { Save.class, Update.class })
    private String uriName;

    /**
     * 接口路径
     */
    @NotBlank(message = "接口路径不能为空", groups = { Save.class, Update.class })
    private String uri;

    /**
     * 权限标识(多个用逗号分隔，如：xx:xx,yyy:yyy)
     */
    private String permit;

    /**
     * 接口类型[0-包 1-值]
     */
    @NotNull(message = "接口类型不能为空", groups = { Save.class, Update.class })
    private Integer type;

    /**
     * 校验模式[0-全值匹配 1-模糊匹配]
     */
    @NotNull(message = "校验模式不能为空", groups = { Save.class, Update.class })
    private Integer checkMode;

    /**
     * 接口标签[0-新增 1-查询 2-修改 3-删除]
     */
    @NotNull(message = "接口标签不能为空", groups = { Save.class, Update.class })
    private Integer label;

    /**
     * 备注
     */
    private String remark;

    /**
     * 校验属性枚举值
     * @return 错误提示
     */
    public String isEnumFail() {
        if (UriEnum.NULL == UriEnum.getCheckModeEnum(checkMode)) {
            return "校验模式值错误";
        }
        if (UriEnum.NULL == UriEnum.getLabelEnum(checkMode)) {
            return "接口标签值错误";
        }
        return null;
    }
}
